package com.hqyj.ssm.controller;/*
 * ClassName  UserController
 * @Author： AJA
 * @Description ：TODO
 *
 * @Date  2022/1/5 11:20
 * @Version 1.0
 **/

import com.hqyj.ssm.pojo.User;
import com.hqyj.ssm.service.UserService;
import com.hqyj.ssm.utils.ResultInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller//表名
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    //login
    @RequestMapping("/login")
    @ResponseBody
    public ResultInfo login(String username,String password){
        return userService.login(username,password);
    }

    //logout
    @RequestMapping("/logout")
    @ResponseBody
    public String logout(){
        SecurityUtils.getSubject().logout();
        return "login";
    }

    @RequestMapping("/selectAll")
    @ResponseBody
    public ResultInfo selectAll(int pageNum,int pageSize,String username){
        return userService.selectAll(pageNum,pageSize,username);
    }
    @RequestMapping("/insertUser")
    @ResponseBody
    public ResultInfo insertUser(User user){
        return userService.insertUser(user);
    }
    @RequestMapping("/deleteUserByUsername")
    @ResponseBody
    public ResultInfo deleteUserByUsername(String username){
        return userService.deleteUserByUsername(username);
    }
    @RequestMapping("/updateUserByUsername")
    @ResponseBody
    public ResultInfo updateUserByUsername(User user){
        return userService.updateUserByUsername(user);
    }

    @RequestMapping("/checkUsername")
    @ResponseBody
    public ResultInfo checkUsername(String username){
        return userService.checkUsername(username);
    }
}
